Ext.define('Jason.view.protal.module.systemSetting.runSql.MainView',{
	extend : 'Ext.container.Container',
	requires: [
		'Ext.tab.Panel',
		'Wys.form.field.CodeField',
		'Wys.combobox.ComboTree',
		'Jason.model.Model',
		'Jason.store.module.systemSetting.RunSqlStore',
		'Jason.view.protal.module.systemSetting.runSql.MainViewModel',
		'Jason.view.protal.module.systemSetting.runSql.MainViewCtrl'
	],
	controller: 'runSqlViewCtrl',
	viewModel: {type:'runSqlViewModel'},
	xtype : 'runSqlView',
	alias : 'weight.runSqlView',
	layout:{type : 'border'},
	items:[{
		region:'west', 
		itemId : 'tableAndView',
		xtype : 'treepanel',width:250,
		collapsible: true,
		title : '表/视图',
		reserveScrollbar: true,
		containerScroll:true,
        useArrows: true,
        rootVisible: false,
		store:Ext.create('Ext.data.TreeStore',{
			autoLoad:false,
			fields:['text','id','children','leaf'],
			root:{
				expanded: true,
				text:'root'
			},
			proxy: {
				type:'ajax',
				api: {
		            read: reqUrl.systemSetting.dataSouce.getDbTableAndViewByTree
		        },
		        reader: {
		            totalProperty: 'total',
		            successProperty: 'success'
		        }
			}
		})
	},{
		height:300,
		xtype : 'tabpanel',
		region:'north',
		split: true,     //允许用户自定义调整窗口大小
	    frame: true,      //显示边框
	    header:false,
	    collapsed: false,  //折叠状态
	    titleCollapse: true,  //点击子元素的标题就可以折叠
	    collapsible: true,     //可以折叠内容区
		autoScroll:true,
		items:[{
			title:'Query Editor',
			layout:'fit',border:true,
			dockedItems:[{
				xtype : 'toolbar',
				dock : 'top',
				items:[{
					xtype : 'comboTree',emptyText:'请选择连接',
					itemId:'dataSourceCombo',
					listeners:{
						select:function(comb){
							var tBStore = comb.up('runSqlView').down('#tableAndView').getStore();
							Ext.apply(tBStore.proxy.extraParams,{
								code: comb.getValue()
							});
							tBStore.load();
						}
					},
					store:Ext.create('Ext.data.TreeStore',{
						fields:[],
						proxy:{
							type: 'ajax',
							api:{
								read: reqUrl.systemSetting.dataSouce.findByTree
							}
						}
					})
				},{
					xtype : 'button',
					ui : 'btn-success-round',
					iconCls : 'fa-play',
					listeners:{click:'onRunSQlBtn'},
					text: '运行'
				}]
			}],
			items:[{
				xtype : 'codeField',
				mode:'text/x-sql',
				// xtype : 'textarea',
				itemId:'sqlInput',
				emptyText:'请输入要执行的SQL语句',
				flex:1,width:'100%',anchor:'100%'
			}]
		},{
			title:'Query History'
		}]
	},{
		xtype : 'tabpanel',flex: 1,border:true,region:'center',
		items:[{
			title:'信息',itemId:'runSqlMsg',html:'>>欢迎使用数据在线浏览工具，您可以在这里执行标准SQL语句进行数据管理'
		},{
			title:'数据输出',xtype : 'baseView',itemId:'dataResult',
			bind:'{sysRunSqlStore}',
			dockedItems: [{
		        xtype: 'pagingtoolbar',
		        enabledMoreOpt: true,
		        bind: '{sysRunSqlStore}',
		        dock: 'bottom'
		    }]
		}]
	}]
})